home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung / Power-Programmierung (Tewi)(1994).iso / magazine / nan_news / toolkit / acctmnth.prg < prev    next >
Text File  |  1991-08-15  |  5KB  |  128 lines

  1. /*
  2.  * File......: ACCTMNTH.PRG
  3.  * Author....: Jo W. French dba Practical Computing
  4.  * CIS ID....: 74731,1751
  5.  * Date......: $Date:   15 Aug 1991 23:02:30  $
  6.  * Revision..: $Revision:   1.2  $
  7.  * Log file..: $Logfile:   E:/nanfor/src/acctmnth.prv  $
  8.  * 
  9.  * The functions contained herein are the original work of Jo W. French
  10.  * and are placed in the public domain.
  11.  *
  12.  * Modification history:
  13.  * ---------------------
  14.  *
  15.  * $Log:   E:/nanfor/src/acctmnth.prv  $
  16.  * 
  17.  *    Rev 1.2   15 Aug 1991 23:02:30   GLENN
  18.  * Forest Belt proofread/edited/cleaned up doc
  19.  * 
  20.  *    Rev 1.1   14 Jun 1991 19:50:42   GLENN
  21.  * Minor edit to file header
  22.  * 
  23.  *    Rev 1.0   01 Apr 1991 01:00:24   GLENN
  24.  * Nanforum Toolkit
  25.  *
  26.  */
  27.  
  28. /*  $DOC$
  29.  *  $FUNCNAME$
  30.  *     FT_ACCTMONTH()
  31.  *  $CATEGORY$
  32.  *     Date/Time
  33.  *  $ONELINER$
  34.  *     Return accounting month data
  35.  *  $SYNTAX$
  36.  *     FT_ACCTMONTH( [ <dGivenDate> ], [ <nMonthNum> ] ) -> aDateInfo
  37.  *  $ARGUMENTS$
  38.  *     <dGivenDate> is any valid date in any date format.  Defaults
  39.  *     to current system date if not supplied.
  40.  *
  41.  *     <nMonthNum> is a number from 1 to 12 signifying a month.
  42.  *     Defaults to current month if not supplied.
  43.  *  $RETURNS$
  44.  *     A three element array containing the following data:
  45.  *
  46.  *        aDateInfo[1] - The year and month as a character string "YYYYMM"
  47.  *        aDateInfo[2] - The beginning date of the accounting month
  48.  *        aDateInfo[3] - The ending date of the accounting month
  49.  *  $DESCRIPTION$
  50.  *     FT_ACCTMONTH() creates an array containing data about the
  51.  *     accounting month containing the given date.
  52.  *
  53.  *     An accounting period has the following characteristics:
  54.  *
  55.  *     If the first week of the period contains 4 or more 'work'
  56.  *     days, it is included in the period; otherwise, the first
  57.  *     week was included in the prior period.
  58.  *
  59.  *     If the last week of the period contains 4 or more 'work'
  60.  *     days it is included in the period; otherwise, the last week
  61.  *     is included in the next period.  This results in 13 week
  62.  *     'quarters' and 4 or 5 week 'months'.  Every 5 or 6 years, a
  63.  *     'quarter' will contain 14 weeks and the year will contain 53
  64.  *     weeks.
  65.  *  $EXAMPLES$
  66.  *     // get info about accounting month containing 9/15/90
  67.  *     aDateInfo := FT_ACCTMONTH( Ctod("09/15/90") )
  68.  *     ? aDateInfo[1]   //  199009       (9th month)
  69.  *     ? aDateInfo[2]   //  09/02/90     beginning of month 9
  70.  *     ? aDateInfo[3]   //  09/29/90     end of month 9
  71.  *
  72.  *     // get info about accounting month 5 in year containing 9/15/90
  73.  *     aDateInfo := FT_ACCTMONTH( Ctod("09/15/90"), 5 )
  74.  *     ? aDateInfo[1]   //  199005
  75.  *     ? aDateInfo[2]   //  04/29/89   beginning of month 5
  76.  *     ? aDateInfo[3]   //  06/02/90   end of month 5
  77.  *  $SEEALSO$
  78.  *     FT_DATECNFG() FT_ACCTWEEK() FT_ACCTQTR() FT_ACCTYEAR()
  79.  *  $END$
  80. */
  81.  
  82. FUNCTION FT_ACCTMONTH(dGivenDate,nMonthNum)
  83. LOCAL nYTemp, nMTemp, lIsMonth, aRetVal
  84.  
  85. IF dGivenDate == NIL .OR. !VALTYPE(dGivenDate) $ 'ND'
  86.   dGivenDate := DATE()
  87. ELSEIF VALTYPE(dGivenDate) == 'N'
  88.   nMonthNum := dGivenDate
  89.   dGivenDate := DATE()
  90. ENDIF
  91. lIsMonth := IF(nMonthNum == NIL .OR. VALTYPE(nMonthNum) != 'N', .F., .T.)
  92. nMonthNum := IF(lIsMonth, IF(nMonthNum > 0 .AND. nMonthNum < 13, ;
  93.                              nMonthNum, 12), NIL)
  94.  
  95. aRetVal := FT_MONTH(dGivenDate)
  96. nYTemp := VAL(SUBSTR(aRetVal[1],1,4))
  97. nMTemp := VAL(SUBSTR(aRetVal[1],5,2))
  98. aRetVal[2] := FT_ACCTADJ(aRetVal[2])
  99. aRetVal[3] := FT_ACCTADJ(aRetVal[3], .T. )
  100.  
  101. IF dGivenDate >= aRetVal[2] .AND. dGivenDate <= aRetVal[3]
  102.   * All Ok
  103. ELSEIF dGivenDate < aRetVal[2]
  104.   dGivenDate := FT_MADD(dGivenDate, -1)
  105.   aRetVal := FT_MONTH(dGivenDate)
  106.   nYTemp := IF(nMTemp - 1 > 0, nYTemp, nYTemp - 1)
  107.   nMTemp := IF(nMTemp - 1 > 0, nMTemp -1, 12)
  108.   aRetVal[2] := FT_ACCTADJ(aRetVal[2])
  109.   aRetVal[3] := FT_ACCTADJ(aRetVal[3], .T. )
  110. ELSE
  111.   dGivenDate := FT_MADD(dGivenDate, 1)
  112.   aRetVal := FT_MONTH(dGivenDate)
  113.   nYTemp := IF(nMTemp + 1 < 13, nYTemp, nYTemp + 1)
  114.   nMTemp := IF(nMTemp + 1 < 13, nMTemp +1, 1)
  115.   aRetVal[2] := FT_ACCTADJ(aRetVal[2])
  116.   aRetVal[3] := FT_ACCTADJ(aRetVal[3], .T. )
  117. ENDIF
  118. IF lIsMonth
  119.   aRetVal := FT_MONTH(dGivenDate, nMonthNum)
  120.   nYTemp := VAL(SUBSTR(aRetVal[1],1,4))
  121.   nMTemp := VAL(SUBSTR(aRetVal[1],5,2))
  122.   aRetVal[2] := FT_ACCTADJ(aRetVal[2])
  123.   aRetVal[3] := FT_ACCTADJ(aRetVal[3], .T. )
  124. ENDIF
  125. aRetVal[1] := STR(nYTemp,4) + PADL(LTRIM(STR(nMTemp,2)), 2, '0')
  126. RETURN aRetVal
  127.  
  128.